Magic Creation
. Magic Creation is a feature exclusive to Nightshade: Online. This feature allows players to create their own magic in-depth by using a modified version of the Lua scripting language, we will call this NSLua to differentiate from pure and modified. Overview The Magic Creation window has three tabs: Statistics, Writer and Console. Each of these windows serves their own purposes. Statistics The Statistics windows show information about the magic you're creating and it also allows you to input data for your skill (Name and Description). There are five stats that are shown about your skill. Total Damage This is the total damage your skill does. Top Speed This is the fastest speed your skill goes. Top Duration This is the longest your skill is active. Skill Cost This is the cost of mana to execute this skill. The cost increased based on what functions are used in the skill. Damage, Status Effects, Buffs/Debuffs and other functions increase this cost. It's possible to create an amazing strong skill, however, without enough mana you simply cannot execute it. Skill Tier This is the tier your skill is in. The tier depends on the skill cost. Writer The Writer window is where you actually write all the code for your skill. Console The Console shows messages sent from your skill. This is useful for debugging. To send a message to the console please use the function print(string). Writer Writing skills may be challenging initially, it is, however, easy to learn. Comments Comments are code that isn't actually run. It's useful for writing notes or explaining what you wrote. To create a comment simply use double dashes (--). We can also make multiline comments by opening with two dashes and two brackets and then closing with the opposite. Here is an example: Data Types In Lua, there are a few different data types. Number The Number Data Type include: -784,-783,...,0,1,2,3,...,10.32,10.33,...10302,10303. Basically, any number that you can write is the Number Data Type. Boolean Booleans only have two values: true or false, on or off, yes or no, however you like to remember it. String Strings include words, sentences, letters, anything that are between quotations. Examples of strings are "Boy!!!", 'Wow, this is pretty cool!' (Notice we used single quotes instead of double? You can do both, they're the same), "a". Technically, strings aren't really words or sentences, they're anything between quotation marks, so the following can also be considered strings: "1231", 'true','3.14'. Like comments, strings can also be split over multiple lines by using double brackets instead of quotations. Nil When we want to specify "nothing" we simply use the nil data type. Nil basically means "nothing". Variables The most basic feature that Lua has are variables. Variables are sort of like nicknames. Let's see how they work: From this we can see that to make a new variable, we simply type the following: What can we call these variables? Anything really as long as they don't start with a number and don't contain spaces. The value of the variable can vary from numbers, strings, booleans (true or false, pretty simple) and other data types (you'll learn more about them). Flow Control If/Else/Elseif Statements We can run code only if it passes a "gate". These gates are called if statements. The usage is straight-forward: Something that you might have noticed is the use of double equals ( ), when we set something we use one equal sign but if we are checking if something equals something else, we use double. So, will it pass the gate? Let's see. We first set the ARandomNumber variable to 5 which basically means that those two are equivalent. Now to our if statement: We know that ARandomNumber is equal to 5 so if we replace that, we get: We can easily tell that this is true (correct) and so it passes the gate. Now the code below it will run. However, when we say "below", what do we really mean. Well, in Lua's case, below means until we reach the end keyword. Anything between the if statement and end will be ran because it passed the if statement. Now that we saw how if statements work, let's see their usage: The double equal was only one of the few comparison operators in Lua. Here is a table of all comparison operators: Let's suppose that our if statement doesn't pass, where does it go? Well, it just skips that whole "block" and continues after the end. What if we want to run some code if it fails to pass though? Lua allows us to do this easily, we simply use the else keyword. Usage: Let's read our code above. First, we have an if statement that checks if 5+5 10. If that's true, it will run the code below. In the code below, there's something interesting... What's this print? print '''is a function. We'll talk about functions soon enough, all you need to know is that we can print anything in the console by using this function. We write what we want to print between the brackets (print(whatever_you_want_here)) In this case, the condition is true so the gate will run the code below it and thus, run the print function. Let's assume that this wasn't the case. With this assumption, the code won't run what's below the if statement but instead what's below the '''else keyword! So assuming 5+5 wasn't 10, it would run the code under else. In our output, we would see: "5+5 is not 10, where are we???". What if we wanted to do another check if the previous one failed? We can always do something like: This would most certainly work, though, it doesn't look pleasant, at all. We can use the keyword elseif to do another check instead of nesting two if statements. This looks much cleaner and actually runs more efficiently (better)! Loops What if we want to repeat a specific piece of code multiple times? Sure, we can just copy and paste away but what if we need to repeat a piece of code 100s, 1000s or even more times? Surely, copy and pasting would work but that would simply take too long. Loops help us do this quickly. There are three types of loops, I will only mention two of them simply because the third one is barely used. While Loop Let's get right to the usage: If you remember from the Flow Control section, you'll remember that if statements are structured similarily. While loops will continue to run the code under it as long as the condition is true. Let's see an example: Let's look at this analytically. First, we see that the condition is the following: 10/2 5. The / '''operator is used to divide numbers. So obviously, 10 divided by 2 is 5. So the the code below it will run. However, it will never stop running. 10 divided by 2 will always be 5, so how can we stop this? We can use the '''break statement. This will stop the loop and continue on with the script. An example: This will only print once because after the first loop it will stop the loop (because of the break statement). In this case, it doesn't make much sense, so here is a better example using everything we've learned so far. First, we create a variable n and set it's value to 1. We then create a while loop which runs as long as true is true (so runs forever). Each time we loop, we increase n by 1, print the current value of n and then check if n is larger than 50. If it is, it stops the while loop. For Loops Again, let's get right to the point. Unlike the while loop, there is no condition but instead three parameters. First we create a temporary variable called "i" (it can be called anything), we set this to whatever number we want to start at (usually 1). The "end_" parameter is set to whatever number that '''i '''has to be equal to for the loop to break. Finally, we have step. Step is how much i increased for each loop, if you leave this blank it will assume you want a step of 1. Now, that's a lot to take in, so let's see another example: The for loop will repeat the code below it for a total of 25 times, it will print the following: Like while loops, you can use '''break '''to stop the loop. Category:API Category:A to Z